<template>
	<view class="warp">
	<view class="form">
		<uni-forms :modelValue="querform"  label-width ="260" label-position="left" :border="true">
	<uni-forms-item class="formitem"  label="公司名称" name="activityTitle" >
		<input placeholder-style="" v-model="querform.company"  type="text" placeholder="请输入公司名称(必填)">
	</uni-forms-item>
	<uni-forms-item>
		<view class="companyclass">
			<view class="list">
				<view @click="tabclass(item,index)" class="item" :class="classnum==index?'item active':'item'" v-for="(item,index) in classlist" :key="index">
					{{item.name}}
				</view>
			</view>
		</view>
	</uni-forms-item>
	
	<uni-forms-item class="formitem" label="职位" name="activityStartTime"    >
		<input  v-model="querform.job"  type="text" placeholder="请输入职位">
	</uni-forms-item>
	<uni-forms-item class="formitem" label="姓名" name="activityEndTime"  >
		<input  v-model="querform.name"  type="text" placeholder="请输入姓名(必填)">
	</uni-forms-item>
	<uni-forms-item class="formitem" label="电话" name="activityEndTime"  >
		<input  v-model="querform.phone"  type="text" placeholder="请输入联系电话(必填)">
	</uni-forms-item>
	</uni-forms>
	<!-- <view class="price">
		<view class="title">
			价格
		</view>
		<view class="pricenum">
			99
		</view>
	</view> -->
	
	</view>
	
	<positionIfor @lodAddress="getLocation()"></positionIfor>
	<view class="b_submit">
		<view class="submit" @click="submit">
			提交
		</view>
	</view>
	</view>
</template>

<script>
	import uniForms from "../uni-forms/components/uni-forms/uni-forms.vue"
	 import uniFormsItem from "../uni-forms/components/uni-forms-item/uni-forms-item.vue"
	import positionIfor from '@/components/position_info.vue';
	import { mapState} from 'vuex';
	export default {
		components:{
			uniForms,
			uniFormsItem,
			positionIfor
		},
		data() {
			return {
				querform:{
					attendActivityId: '', //活动id
					name: "", //姓名
					phone: "", //手机
					company: "", //公司
					job: "" ,//工作
					wxPhone:'',//微信手机号
					detailAddress:'',//详细地址
					workType:'施工商',//类型
					// attendType:'1'
				},
				activityinfo:{},
				paySn:null,
				classlist:[
					{name:'施工商',id:1},
					{name:'材料商',id:2},
					{name:'业主',id:3},
					{name:'其他',id:4}
				],
				classnum:0,//
				address:''
			};
		},
		computed:{
			...mapState(['hasLogin', 'userInfo', 'userCenterData']),
		},
		onLoad(e) {
			this.getactivityinfo(e)
		},
		methods:{
			// 选择公司分类
			tabclass(val,idx){
				this.classnum=idx
				this.querform.workType=val.name
			},
			// 定位
			getLocation(address){
				console.log(address,'777');
			   	// address就是组件传出的具体位置
				
			   	this.address = address;
								uni.setStorageSync('address', this.address);
								 setTimeout(()=>{
									 console.log(uni.getStorageSync('address'),3434344);
								 },500)
							},
			   //获取总览数据
			// 提交
			submit(){
				// #ifdef H5
				this.order_from = 2
				// #endif
				
				// #ifdef APP-PLUS
				switch (uni.getSystemInfoSync().platform) {
					case 'android':
						this.order_from = 3
						break
					case 'ios':
						this.order_from = 4
						break
					default:
						break
				}
				// #endif
				
				// #ifdef MP-WEIXIN
				this.order_from = 5
				// #endif
				
				// #ifdef MP-BAIDU
				this.order_from = 7
				// #endif
				
				// #ifdef MP-ALIPAY
				this.order_from = 8
				// #endif
				
				// #ifdef MP-TOUTIAO
				this.order_from = 9
				// #endif
				if(this.querform.company.length==0){
					uni.showToast({
						title:'请填写公司名称',
						icon:'none'
					})
				}else if(this.querform.name.length==0){
					uni.showToast({
						title:'请填写姓名',
						icon:'none'
					})
				}else if(this.querform.phone==0){
					uni.showToast({
						title:'请填写电话',
						icon:'none'
					})
				}else{
					this.querform.detailAddress=this.address
					this.querform.wxPhone=this.userCenterData.memberMobile
					// 提交报名信息
					this.$request({
						url:'v3/activity/front/activity/attend/add',
						method:"POST",
						header : {
							'Content-Type': 'application/json'
						},
						data:this.querform
					}).then(res=>{
						if(res.state==200){
							uni.showToast({
								title:'报名信息添加成功',
								icon:'none'
							})
							this.querform={
					attendActivityId: '', //活动id
					name: "", //姓名
					phone: "", //手机
					company: "", //公司
					job: "" //工作
				}
							setTimeout(()=>{
								if(res.state==200 && this.activityinfo.productId){
									
									setTimeout(()=>{
										uni.showToast({
											title:'本次报名需要购买相应产品',
											icon:'none'
										})
										setTimeout(()=>{
												this.$Router.push({
													path:'/pages/order/confirmOrder',
													query:{
														productId:this.activityinfo.productId,
														orderType:1,
														ifcart:2,
														numbers:1
														// goodsId:this.activityinfo.goodsId
													}
												})
											
										},1000)
									},1000)
									
									
								} else{
									uni.navigateBack({delta:1})
								}
							},2000)
						}
					})
					
					// this.$request({
					// 	url:'v3/business/front/orderOperate/confirm',
					// 	method:'POST',
					// 	header : {
					// 		'Content-Type': 'application/json'
					// 	},
					// 	data:{
					// 		productId:'200001060002',
					// 		isCart:false,
					// 		number:6,
					// 		isAloneBuy:true,
					// 		orderFrom:2,
					// 		source: 1,
							
					// 	}
					// }).then(res=>{
					// 	if(res.state==200){
					// 		// 模拟提交订单
					// 		this.$request({
					// 			url:'v3/business/front/orderOperate/submit',
					// 			method:'POST',
					// 			header : {
					// 				'Content-Type': 'application/json'
					// 			},
					// 			data:{
					// 				productId:'200001060002',
					// 				isCart:false,
					// 				number:6,
					// 				isAloneBuy:true,
					// 				orderFrom:2,
					// 				source: 3,
									
					// 			}
					// 		}).then(resn=>{
					// 			this.paySn=resn.data.paySn
					// 			// 模拟提交订单
					// 			this.$Router.replace({
					// 				path: '/pages/order/pay',
					// 				query: {
					// 					paySn:resn.data.paySn,
					// 					payMethodType: 'create'
					// 				}
					// 			})
					// 		})
					// 	}
					// })
					
					
					
				}
				
			},
			// 获取活动详情
			getactivityinfo(val){
				this.$request({
					url:'v3/activity/front/activity/detail/'+val.id,
					method:'GET'
				}).then(res=>{
					this.activityinfo=res.data
					this.querform.attendActivityId=this.activityinfo.activityId
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
page{
			width: 750rpx;
			margin: 0 auto;
			background: #F5F5F5;
			overflow: hidden;
		}
		.warp{
			background-color: #fff;
			.form{
				padding: 10rpx 30rpx;
				margin-top: 10rpx;
			.companyclass{
				.list{
					display: flex;
					
					
					.item{
						padding: 6rpx 20rpx;
						font-size: 24rpx;
						height: 58rpx;
						line-height: 48rpx;
						border: 2rpx solid #c3c3c3;
						border-radius: 30rpx;
						margin-right: 20rpx;
					}
					.active{
						color: #ff841f;
						border: 2rpx solid #ff841f;
					}
				}
			}
				.formitem{
					width: 100%;
					height: 70rpx;
					display: flex !important;
					align-items: center !important;
					
				}
				/deep/.uni-forms-item{
					display: flex !important;
					align-items: center !important;
				}
				.price{
					margin-top: 10rpx;
					border-top: 2rpx solid #c3c3c3;
					padding: 20rpx 0;
					display: flex;
					justify-content: space-between;
					.pricenum{
						color: red;
						font-size: 32rpx;
					}
				}
			}
			.b_submit{
			position: fixed;
			bottom: 10rpx;
			left: 26%;
			.submit{
				text-align: center;
				line-height: 80rpx;
				color: #fff;
				font-size: 32rpx;
				width: 360rpx;
				height: 80rpx;
				background-color:  #ff841f;
				border-radius: 40rpx;
			}
			}
		}
</style>
